#include "hi_go.h"
#include "hi_gv.h"
#include <stdio.h>
#include <string.h>
#include "higv_cextfile.h"
#include "sample_utils.h"
#include "higv_language.h"
#include "hi_gv_parser.h"
#include "hi_gv_input.h"

#ifdef __cplusplus
#if __cplusplus
    extern "C"{
#endif
#endif /*  __cplusplus  */

// text数目
#define HIGV_CONTROL_PAGENUM  15
// #define HIGV_CONTROL_PAGENUM  2
// inmage数目++++
HI_U32 g_selItem = 0; // 设置初始焦点，并将tap初始值设置为g_selItem的首次值
#define PIC_COUNT 12  // 图片预览的图片单元格总数，实际情况应当以数据库为准
// #define PIC_COUNT 2  // 图片预览的图片单元格总数，实际情况应当以数据库为准
#define FILE_LEN  128 // 图片文件的路径名长度，须预留结束符，与datamodel.xml字段中的长度保持一致
static HI_CHAR g_scaleImgFile[PIC_COUNT][FILE_LEN] = {
    {"./res/pic/scaleview/1.JPG"},
    {"./res/pic/scaleview/2.JPG"},
    {"./res/pic/scaleview/3.JPG"},
    {"./res/pic/scaleview/4.JPG"},
    {"./res/pic/scaleview/5.JPG"},
    {"./res/pic/scaleview/6.JPG"},
    {"./res/pic/scaleview/7.JPG"},
    {"./res/pic/scaleview/8.JPG"},
    {"./res/pic/scaleview/9.JPG"},
    {"./res/pic/scaleview/10.JPG"},
    {"./res/pic/scaleview/1.JPG"},
    {"./res/pic/scaleview/2.JPG"}
};

HI_S32 SCALEVIEW_WIN_onhide(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
    return HIGV_PROC_GOON;
}

HI_S32 SCALEVIEW_WIN_IMAGE1_ontouchaction(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
    (HI_VOID)HI_GV_Widget_Show(MAIN_WIN);
    (HI_VOID)HI_GV_Widget_Active(MAIN_WIN);
    (HI_VOID)HI_GV_Widget_Hide(SCALEVIEW_WIN);
    return HIGV_PROC_GOON;
}

HI_S32 SCALEViewOnShowListener(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
 /* 字体条目数据模型
    HI_S32 s32Ret;
    HI_U32 u32Index = 0;
    HIGV_HANDLE hDDB = 0;
    HIGV_DBROW_S stDbRow;
    //  HI_U32 StrSet[HIGV_CONTROL_PAGENUM] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
    HI_U32 StrSet[HIGV_CONTROL_PAGENUM] = {1,2};
    s32Ret = HI_GV_ADM_GetDDBHandle(ADM_NUM, &hDDB);
    if (HI_SUCCESS != s32Ret)
    {
        printf("Failed to add data, function:<%s>, retval %#x.\n", __FUNCTION__, s32Ret);
        return -1;
    }
    HI_GV_DDB_EnableDataChange(hDDB, HI_FALSE);
    HI_GV_DDB_Clear(hDDB);
    for (u32Index = 0; u32Index < HIGV_CONTROL_PAGENUM; u32Index++)
    {
        memset(&stDbRow, 0x00, sizeof(stDbRow));
        stDbRow.pData = &StrSet[u32Index];
        stDbRow.Size  = sizeof(HI_U32);
        HI_GV_DDB_Append(hDDB, &stDbRow);
    }
    HI_GV_DDB_EnableDataChange(hDDB, HI_TRUE);
    HI_GV_ADM_Sync(ADM_NUM); */
    // +++图片类++++++++
    HI_GV_ADM_Sync(ADM_SCALEIMAGE);
    // ++测试用例-----------------------
    HI_U32 Num = 0 ;
    // HI_GV_SCALEVIEW_SetSelItem(MENUSET_SCALEVIE,2);
    HI_GV_SCALEVIEW_GetSelItem(MENUSET_SCALEVIE, &g_selItem);
    printf("[Func: %s, Line: %d, HI_GV_SCALEVIEW_GetSelItem:%d] \n\n", __FUNCTION__, __LINE__, g_selItem);
    HI_GV_SCALEVIEW_GetItemNum(MENUSET_SCALEVIE, &Num);
    printf("[Func: %s, Line: %d, HI_GV_ScaleView_GetItemNum:%d] \n\n", __FUNCTION__, __LINE__, Num);

    return HIGV_PROC_GOON;
}
HI_S32 scaleGridGetCount(HIGV_HANDLE DBSource, HI_U32 *RowCnt)
{   // +++图片类++++++++
    *RowCnt = PIC_COUNT;
    return HI_SUCCESS;
}
/* * +++ userdb获取数据内容回调函数，对应datamodel.xml中的"getrowvalue" +++
    DBSource: 回调该函数的ADM句柄
    Row:      起始行索引，在scaleview中表现为单元格索引
    Num:      本次获取的缓冲行数(Cell number)，奇数
    pData:    数据传出指针
    pRowNum:  传出数据的真实行数 在scaleview中表现为单元格数 */
HI_S32 scaleGridGetValue(HIGV_HANDLE DBSource, HI_U32 Row, HI_U32 Num, HI_VOID *pData, HI_U32 *pRowNum)
{
    // +++图片类++++++++
    HI_U32 i = Row;
    HI_U32 j = 0;
    HI_U32 RowNum = 0;
    for (j = 0; i < PIC_COUNT && j < Num ; i++, j++) {
        /* * 将输入拷贝给传出指针，因为会将字段填满0，可以不拷贝结束符* */
        memcpy(pData, g_scaleImgFile[i], strlen(g_scaleImgFile[i]));
        /* * 将字段填满0，字段长度为datamodel字段的长度 */
        memset((char*)pData + strlen(g_scaleImgFile[i]), 0x0, FILE_LEN - strlen(g_scaleImgFile[i]));
        RowNum++;
    }
    *pRowNum = RowNum;
    return HI_SUCCESS;
}

HI_S32 scaleGridRegister(HIGV_HANDLE DBSource, HIGV_HANDLE hADM)
{
    return HI_SUCCESS;
}

HI_S32 scaleGridUnregister(HIGV_HANDLE DBSource, HIGV_HANDLE hADM)
{
    return HI_SUCCESS;
}

HI_S32 OntouchListener(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
    // 测试用例：
    HI_U32 selectItem = -1 ;
    HI_GV_SCALEVIEW_GetFoucItem(MENUSET_SCALEVIE, &selectItem);
    //printf("[Func: %s, Line: %d, wParam:%d] \n\n", __FUNCTION__, __LINE__, selectItem);
    return HIGV_PROC_GOON;
}

HI_S32 OnTapListener(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
    // 测试用例：
    HI_U32 tapItem = -1 ;
    HI_GV_SCALEVIEW_GetTapItem(MENUSET_SCALEVIE, &tapItem);
    //printf("[Func: %s, Line: %d,HI_GV_ScaleView_GetTapItem:%d] \n\n", __FUNCTION__, __LINE__, tapItem);
    return HIGV_PROC_GOON;
}

HI_S32 OnFocusSelectListener(HIGV_HANDLE hWidget, HI_PARAM wParam, HI_PARAM lParam)
{
    // 测试用例：
    // 第二个参数就是焦点条目
    //printf("[Func: %s, Line: %d, wParam:%d] \n\n", __FUNCTION__, __LINE__, wParam);
    return HIGV_PROC_GOON;
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /*  __cplusplus  */

